<template>
	<view>
		<!-- 优惠券弹窗 -->
		<uni-popup ref="cpopup" type="bottom">
			<view class="pop">
				<view class="ptitle f32 tr">优惠券</view>
				<u-tabs :list="couponTypeData" @click='getCoupon' v-if="isShowCouponTabs && mer_id"></u-tabs>
				<view class="plist" v-if="quan_list.length && isSwitch == false">
					<scroll-view scroll-y="true" class="plist-scroll">
						<view class="plist2 flex" v-for="(item,index) in quan_list" :key="index">
							<view class="lleft fh-ct">
								<view class="f24 red">￥<text class="f40 red">{{item.coupon_price}}</text></view>
								<view class="f22" v-if='item.use_min_price > 0'>满{{item.use_min_price}}可用</view>
								<view class="f22" v-else>无门槛</view>
							</view>
							<view class="lright">
								<view class="one f26">{{item.title}}</view>
								<view class="two f24">
									<view v-if="item.is_timeout">
										{{item.start_time}}-{{item.end_time}}
									</view>
									<view v-else>
										不限时
									</view>
									<view class="lright-lq" v-if="item.issue">
										已领取
									</view>
									<view class="lright-lq" @click="getQuan2(item)" v-else>
										立即领取
									</view>
								</view>
								<view class="three f22 c999 fw-bt" @click="zhankai(index)">
									<view class="three-desc" :class="!item.look?'hide-line':''" v-if="item.remarks">
										{{item.remarks}}
									</view>
									<view class="three-icon f-w" v-if="item.remarks.length>19">
										<image src="https://jw.xzsw2021.com/static/img/icon_63@2x.png" mode=""
											v-if="!item.look"></image>
										<image src="https://jw.xzsw2021.com/static/img/icon_62@2x.png" mode="" v-else>
										</image>
									</view>
								</view>

							</view>
						</view>
					</scroll-view>
				</view>
				<view class="pnone" v-else-if="!quan_list.length && isSwitch == false">
					<view class="img f-w">
						<image src="https://jw.xzsw2021.com/static/client/icon_100@2x.png" mode=""></image>
					</view>
					<view class="desc f30">暂时没有任何优惠券哦</view>
				</view>

				<view class="plist" v-if="couponData.length && isSwitch">
					<scroll-view scroll-y="true" class="plist-scroll">
						<view class="plist2 flex" v-for="(item,index) in couponData" :key="index">
							<view class="lleft fh-ct">
								<view class="f24 red">￥<text class="f40 red">{{item.coupon_price}}</text></view>
								<view class="f22" v-if='item.use_min_price > 0'>满{{item.use_min_price}}可用</view>
								<view class="f22" v-else>无门槛</view>
							</view>
							<view class="lright">
								<view class="one f26">{{item.title}}</view>
								<view class="two f24">
									<view v-if="item.is_timeout">
										{{item.start_time}}-{{item.end_time}}
									</view>
									<view v-else>
										不限时
									</view>
									<view class="lright-lq" v-if="item.issue">
										已领取
									</view>
									<view class="lright-lq" @click="getQuan2(item)" v-else>
										立即领取
									</view>
								</view>
								<view class="three f22 c999 fw-bt" @click="zhankai(index)">
									<view class="three-desc" :class="!item.look?'hide-line':''" v-if="item.remarks">
										{{item.remarks}}
									</view>
									<view class="three-icon f-w" v-if="item.remarks.length>19">
										<image src="https://jw.xzsw2021.com/static/img/icon_63@2x.png" mode=""
											v-if="!item.look"></image>
										<image src="https://jw.xzsw2021.com/static/img/icon_62@2x.png" mode="" v-else>
										</image>
									</view>
								</view>

							</view>
						</view>
					</scroll-view>
				</view>
				<view class="pnone" v-else-if="!couponData.length && isSwitch">
					<view class="img f-w">
						<image src="https://jw.xzsw2021.com/static/client/icon_100@2x.png" mode=""></image>
					</view>
					<view class="desc f30">暂时没有任何优惠券哦</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		getMerchantCoupon
	} from '@/api/coupon.js'
	export default {
		props: {
			isShow: {
				type: Boolean,
				default: false
			},
			quan_list: {
				type: Array,
				default: []
			},
			isShowCouponTabs: false,
			mer_id: 0
		},
		data() {
			return {
				couponTypeData: [{
					id: 0,
					name: '店铺券'
				}, {
					id: 1,
					name: '商品券'
				}, {
					id: 2,
					name: '免运费'
				}, {
					id: 3,
					name: '满减券'
				}],
				couponData: [],
				isSwitch: false
			}
		},
		onLoad() {
		},
		mounted() {
			
			// this.$refs.cpopup.open()
			uni.$on('openCoupons', (res) => {
				console.log(this.quan_list)
				console.log(this.couponData,'8888888888888888')
				this.$refs.cpopup.open()
			})
			console.log(this.quan_list, 'SADASFASDFASFAS')
		},
		methods: {
			cpopOpen() {
				this.$refs.cpopup.open()
				// if(this.isShow){
				// 	this.$refs.cpopup.open()
				// }else{
				// 	this.$refs.cpopup.close()
				// }
			},
			getCoupon(item) {
				console.log(item)
				this.isSwitch = true
				getMerchantCoupon(this.mer_id, {
					all: item.id
				}).then(res => {
					this.couponData = res.data
				}).catch(err => {

				})
			},
			// 立即领取
			getQuan2(e) {
				// if (this.isSwitch) {
				// 	e.issue = {
				// 		t: "x"
				// 	}
				// }
				this.$emit('getid', e.coupon_id)
				// console.log(e)
			},
			// 展开描述
			zhankai(index) {
				console.log(index);
				this.quan_list[index].look = !this.quan_list[index].look;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.pop {
		// position: relative;
		margin-bottom: 130rpx;
		width: 750rpx;
		height: 745rpx;
		padding: 0 30rpx;
		background-color: #fff;
		border-radius: 30rpx 30rpx 0rpx 0rpx;
		box-sizing: border-box;
		z-index: 999;

		.test {
			height: 30rpx;
			background-color: #18BC37;
		}

		.ptitle {
			padding: 32rpx 0;
		}

		.plist0 {
			height: 600rpx;
		}

		.plist {
			height: 570rpx;

			// overflow-y: auto;
			// &>view:not(:first-child) {
			// 	margin-top: 20rpx;
			// }
			.plist-scroll {
				width: 690rpx;
				height: 570rpx;

				.plist2 {
					margin-bottom: 20rpx;
					width: 690rpx;
					min-height: 186rpx;
					padding: 23rpx 0;
					background: #FFFFFF;
					border: 1rpx solid #FD9D9D;
					border-radius: 10rpx;
					box-sizing: border-box;

					.lleft {
						width: 162rpx;
						height: 140rpx;
						padding: 25rpx 0 0 30rpx;
						// justify-content: center;
						align-items: flex-start;
						box-sizing: border-box;
						border-right: 1rpx dashed #CCCCCC;
					}

					.lright {
						flex: 1;
						position: relative;
						min-height: 140rpx;
						align-items: flex-start;
						padding: 0 30rpx 0 30rpx;

						// background-color: #007AFF;
						.two {
							position: relative;
							margin: 26rpx 0;
						}

						.three {
							min-height: 30rpx;

							.three-desc {
								width: 420rpx;
							}

							.three-icon {
								width: 25rpx;
								height: 12rpx;

								image {
									width: 100%;
									height: 100%;
									// width: 25rpx;
									// height: 12rpx;
								}
							}
						}

						.lright-lq {
							position: absolute;
							right: 0;
							top: 50%;
							transform: translateY(-50%);
							width: 130rpx;
							height: 44rpx;
							text-align: center;
							line-height: 44rpx;
							font-size: 26rpx;
							color: #F83535;
							background: #FFFFFF;
							border: 1rpx solid #F83535;
							border-radius: 22rpx;
							z-index: 6;
						}
					}
				}
			}

		}

		.pnone {
			text-align: center;

			.img {
				margin: 110rpx auto 0;
				width: 376rpx;
				height: 329rpx;
				margin-bottom: 10rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.desc {}
		}
	}
</style>
